// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/store.js'

Vue.config.productionTip = false


import MuseUI from 'muse-ui';
import 'muse-ui/dist/muse-ui.css';
import 'muse-ui-message/dist/muse-ui-message.css';
import 'typeface-roboto';
import Message from 'muse-ui-message';

import Loading from 'muse-ui-loading';

import VueLazyLoad from 'vue-lazyload'



import './style/base/_color.scss';
import './style/base/_mixin.scss';
import './style/base/_reset.scss';
import './style/base/_base.scss';


import api from "@/api/index";
import ApiPath from "@/api/ApiPath"

// 引用配置
import _GLOBAL from "@/config"

// 引用工具
import filters from './utils/filters.js';
import base from './utils/base.js';
import utils from './utils/index.js';

import rules from './utils/rule';

import MyScroll from "@/components/MyScroll/Index.vue"

//挂载到Vue实例上面
Vue.prototype.$api = api
Vue.prototype.ApiPath = ApiPath
Vue.prototype._GLOBAL = _GLOBAL
Vue.prototype.$utils = utils

Vue.prototype.rules = rules

Vue.component('MyScroll', MyScroll);

Vue.use(base);
Vue.use(MuseUI);
Vue.use(filters);
Vue.use(Message);
Vue.use(VueLazyLoad)
Vue.use(Loading,{
	size: 36,
	color: 'secondary',
	classNmae: 'reset-loading'
})
Vue.prototype.Loading = Loading

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})


router.beforeEach((to, from, next) => {
	var _profile = Object.keys(store.getters._get_profile);
	if(to.name == 'Login' && _profile.length > 0 ){
		next({
			path:'/user',
		});
		return ;
	}
	if (to.matched.some(record => record.meta.requireAuth)){ // 判断该路由是否需要登录权限
		// console.log(Object.keys(store.getters._get_profile))
		if(_profile.length == 0){
			next({
				path: '/login',
				query: {redirect: to.path} // 将跳转的路由path作为参数，登录成功后跳转到该路由
			})
		}else{
			next();
		}
		return;
	}
	next();
});
